package scu.maqiang.meshgeneration.rigidmotion;

import scu.maqiang.mesh.*;

public class Ratation2DT3 {
    public static void main(String[] args) {
        Mesh2T3 mesh2D = new Mesh2T3().square2D(100, 100, T3Type.Left);
        double time = 0.0;
        double endTime = 120;
        double dt = 1.0;
        ScalarFunc motionX = (xy, label, param) -> {
            double x = xy[0], y = xy[1];
            double r = Math.sqrt((xy[0] - 0.5) * (xy[0] - 0.5) + (xy[1] - 0.5) * (xy[1] - 0.5));
            if (r < 1.0e-10) {
                return x;
            }
            double cosTheta = (x - 0.5) / r;
            double sinTheta = (y - 0.5) / r;
            double ddt = param[0];
            return r * (cosTheta * Math.cos(Math.PI * ddt / 60) - sinTheta * Math.sin(Math.PI * ddt / 60)) + 0.5;
        };
        ScalarFunc motionY = (xy, label, param) -> {
            double x = xy[0], y = xy[1];
            double r = Math.sqrt((xy[0] - 0.5) * (xy[0] - 0.5) + (xy[1] - 0.5) * (xy[1] - 0.5));
            if (r < 1.0e-10) {
                return y;
            }
            double cosTheta = (x - 0.5) / r;
            double sinTheta = (y - 0.5) / r;
            double t = param[0];
            return r * (sinTheta * Math.cos(Math.PI * t / 60) + cosTheta * Math.sin(Math.PI * t / 60)) + 0.5;
        };
        String fileName = "Rotation.dat";
        mesh2D.toTecplot(fileName, time);
        double[] param = {dt, time};
        while(time < endTime) {
            time += dt;
            System.out.println("time = " + time);
            param[1] = time;
            mesh2D.transform(param, motionX, motionY);
            mesh2D.toTecplot(fileName, time);
        }
    }
}
